package cn.wizzer.app.web.commons.ext.websocket.main.action;

import cn.wizzer.app.web.commons.ext.websocket.main.filter.DefaultNettyFilter;
import cn.wizzer.framework.base.Result;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.Channel;
import org.nutz.ioc.loader.annotation.IocBean;

import java.util.stream.Collectors;

/**
 * 避免重复创建问题此处采用单例模式-注意线程安全
 * 也可以直接将构造函数和instance方法删除直接将action注入到容器中
 *
 * @author 22099
 */
@IocBean
@NettyAction(uri = "/base",filters = {DefaultNettyFilter.class})
public class DefaultNettyAction extends BaseNettyAction {

    @Override
    public Result action(Channel income, JSONObject params) {
        return Result.success().addMsg(params.entrySet().stream().map(entry -> entry.getKey() + ":" + entry.getValue()).collect(Collectors.joining(",")));
    }

    @Override
    public Result subscribe(String subscribeParam) {
        return Result.error("不支持订阅");
    }

}